package com.zx.kitchen.index.common.mvp.presenter;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.zx.kitchen.index.common.entity.ReportDayDetail;
import com.zx.kitchen.index.common.mvp.OnResultListener;
import com.zx.kitchen.index.common.mvp.model.BusinessReportDetailModelImpl;
import com.zx.kitchen.index.common.mvp.model.PurchaseReportDetailModelImpl;
import com.zx.kitchen.index.common.mvp.view.BusinessReportDetailView;

/**
 * Created by Administrator on 2017/3/16.
 */

public class PurchaseReportDetailPresenter implements OnResultListener {

    private BusinessReportDetailView businessReportDetailView;
    private PurchaseReportDetailModelImpl purchaseReportDetailModel;
    private Context mContext;


    public PurchaseReportDetailPresenter(BusinessReportDetailView businessReportDetailView, Context mContext) {
        this.businessReportDetailView = businessReportDetailView;
        this.mContext = mContext;
        purchaseReportDetailModel = new PurchaseReportDetailModelImpl();
    }

    public void getDataFromNet(Context context, String p, String day) {
        purchaseReportDetailModel.getFromNet(0, context, p, day, this, null);
    }


    @Override
    public void onSuccess(int requestCode, String str) {
        ReportDayDetail reportDayDetail = JSON.parseObject(str, new TypeReference<ReportDayDetail>() {
        });
        businessReportDetailView.onSuccess(reportDayDetail);

    }

    @Override
    public void onFailure(int requestCode, String str) {
        businessReportDetailView.onFail(str);
    }
}
